import api, { Relogin } from "../share/api.js";
import { useState, useEffect } from "react";
import { Box, notifications } from "../share/base.js";
import { Datas } from "../app/App";

export default function Home() {
  const [text, setText] = useState("loading");

  useEffect(() => {
    const getData = async () => {
      const res = await api.getTableNames();
      console.log("home: ", res);

      if (res.ok) {
        //setText("Data loaded successfully");
        setText("ok");
        window.location.href = "http://47.99.157.36:50398/";
      } else if (res.status === 300) {
        // login ,authorize
        notifications.show(res.message, "error");
        console.log("ok", res);
        setText(<Relogin />);
      } else {
        // cannot connect to server
        notifications.show(res.message, "error");
      }
    };

    getData();
  }, []); // 这里使用了空的依赖数组，确保只在组件挂载时执行

  return (
    <div>
      <Box />
      {text}
    </div>
  );
}
